/***************************************************************************
 *   Copyright (C) 2008 by JBox systems
 *   gabi@shaargiora.co.il
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 ***************************************************************************/

#pragma once

#include <string>
#include <exception>

/**
	Exception for versions with no installer.
*/
class NoInstaller : public std::exception {
};


/**
	Exception for invalid version folder (like .svn).
*/
class InvalidVersionPath : public std::exception {
};

/**
	@class Version version.h
	A single version of an Application.
	Can be installed with Installer.
*/
class Version {
	/**
		@var m_name Application name.
		@var m_version Application version.
		@var m_path Path to version.
		@var m_installer Path to installer file.
		@var m_params Parameters to be passed to installer.
		@var m_url URL to download installer from.
	*/
	std::string m_name,
					m_version,
					m_path,
					m_installer,
					m_params,
					m_url;

	/**
		Find installer on disk.
	*/
	void findInstallerFile();

	/**
		Set parameters.
	*/
	void setParameters();

	public:

		enum InstallerType {NONE, MSI, EXE};
		Version() { }
		/**
			Usable constructor.
			@param path Path to version's folder.
		*/
		Version(const std::string path, const std::string url="");

		/**
			Default deconstructor.
		*/
		~Version() { }

		/**
			Path to version's folder.
			@return path to folder.
		*/
		std::string path() const { return m_path; }

		/**
			Application's name.
			@return name.
		*/
		std::string name() const { return m_name; }

		/**
			Application's version.
			@return version.
		*/
		std::string version() const { return m_version; }

		/**
			Installer path.
			@returns Path to installer.
		*/
		std::string installer() const { return m_installer; }

		bool hasInstaller() const { return type != NONE; }

		/**
			Installer parameters for current version.
			@return Parameters.
		*/
		std::string parameters() const { return m_params; }

		/**
			Installer download URL.
			@return URL.
		*/
		std::string url() const { return m_url; }

		/**
			Type of the installer for given Version.
		*/
		InstallerType type;

		void setUrl(std::string url) { m_url = url; }

		//for british eyes only:
		bool is_last;
};
